package serviceimpl;

import entity.User;
import mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import service.UserService;
import util.MD5Util;
import util.RedisUtil;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Autowired
    RedisUtil redisUtil;


    @Override
    @Transactional
    public int insert(User user) {
        System.out.println("进入UserServiceImpl");
       if(userMapper.selectByUserName(user.getUsername())==null){
         return userMapper.insertSelective(user);
       }
        return 0;
    }

    public User selectByUserName(String username){

        return userMapper.selectByUserName(username);
    }



    public String selectByUserName(String username,String password){
        User user=userMapper.selectByUserName(username);
        if(user!=null){
         if(MD5Util.checkPassword(password,user.getPassword())){
             return "ok";//用户名密码都正确
         }else{
             return "no";//密码错误
         }
        }else{
            return "notExit";//用户名不存在
        }
    }


}
